package com.gklyj.controller.administer;

import com.gklyj.pojo.Application;
import com.gklyj.pojo.Feedback;
import com.gklyj.service.feedbackService;
import com.gklyj.service.userService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@Transactional
public class feedbackController {

    @Autowired
    feedbackService feedbackService;

    @Autowired
    userService userService;

    @GetMapping("/toAdFeedbackPage")
    public String toAdFeedbackPage(){
        return "administer/feedback";
    }

    /*
    列出处于不同状态的反馈信息
 */
    @GetMapping("/ListDifferenceFeedback")
    @ResponseBody
    public List<Feedback> ListZpApplication(@RequestParam("state") String state){
        String state1 = null;
        //判断返回出于什么状态的申请列表
        if (state.equals("0")){
            state1="未查看";
        }else if (state.equals("1")){
            state1="未解决";
        }else {
            state1="已解决";
        }
        return feedbackService.GetFeedbackByState(state1);
    }

    /*
    查询
     */
    @PostMapping("/searchDifferenceFeedback")
    @ResponseBody
    public List<Feedback> searchDisserenceFeedback(@RequestParam("state") String state,@RequestBody Feedback feedback){
        //若state=0，则为审核中，，=1为已通过，，=2为未通过
        if (state.equals("0")){
            feedback.setState("未查看");
        }else if (state.equals("1")){
            feedback.setState("未解决");
        }else {
            feedback.setState("已解决");
        }
        return feedbackService.SearchDisserenceFeedback(feedback);
    }

    /*
    跳转详情页面
     */
    @GetMapping("/toGetFeedbackDetail")
    public String toGetFeedbackDetail(@RequestParam("id") String id, Model model){
        Feedback feedback = feedbackService.getById(Integer.valueOf(id));
        model.addAttribute("fdetail",feedback);
        return "administer/table/feedback-approval";
    }

    /*
    修改反馈信息状态
     */
    @PostMapping("/ApprovalFeedback")
    @ResponseBody
    public boolean ApprovalFeedback(@RequestBody Feedback feedback) throws RuntimeException{
        return feedbackService.updateById(feedback);
    }
}
